-- @owner: @songjing20
-- @date: 2023-1-14
-- @testpoint: desc/describe分析insert语句
-- @modified by cr13 at 2025/03/18:优化用例

--step1:建表;expect:成功
drop table if exists t_describe_0067 cascade;
create table t_describe_0067(prod_id number(6), cust_id number, time_id date, channel_id char(1), promo_id number(6),
quantity_sold number(3), amount_sold number(10,2)) partition by range (time_id) interval('1 month')
(partition p1 values less than ('2020-01-01 00:00:00'), partition p2 values less than ('2021-01-01 00:00:00'));

--step2:开启事务向表中插入数据(p1分区)，desc/describe分析执行计划，提交;expect:执行成功，打印执行计划
begin;/
desc analyze insert into t_describe_0067 values(1, 12, '2019-01-10 00:00:00', 'a', 1, 1, 1);
describe analyze insert into t_describe_0067 values(1, 12, '2019-01-10 00:00:00', 'a', 1, 1, 1);
end;

--step3:开启事务，向表中插入数据(p2分区)，desc/describe分析insert语句，回滚;expect:回滚插入的数据，打印执行结果
start transaction;
desc analyze insert into t_describe_0067 values(1, 12, '2020-11-10 00:00:00', 'a', 1, 1, 1);
describe analyze insert into t_describe_0067 values(1, 12, '2020-11-10 00:00:00', 'a', 1, 1, 1);
select * from t_describe_0067;
rollback;
select * from t_describe_0067;

--step4:开启事务，向表中插入数据(新增分区)，desc/describe分析insert语句，回滚;expect:回滚插入的数据，打印执行结果
start transaction;
desc analyze insert into t_describe_0067 values(1, 12, '2022-11-24 00:00:00', 'a', 1, 1, 1);
describe analyze insert into t_describe_0067 values(1, 12, '2022-11-24 00:00:00', 'a', 1, 1, 1);
select * from t_describe_0067;
SELECT t1.relname, partstrategy, boundaries FROM pg_partition t1, pg_class t2 WHERE t1.parentid = t2.oid AND t2.relname = 't_describe_0067' AND t1.parttype = 'p';
rollback;
select * from t_describe_0067;
SELECT t1.relname, partstrategy, boundaries FROM pg_partition t1, pg_class t2 WHERE t1.parentid = t2.oid AND t2.relname = 't_describe_0067' AND t1.parttype = 'p';

--step5:清理环境;expect:成功
drop table if exists t_describe_0067 cascade;